package com.ithei.date.异常;

import java.util.ArrayList;
import java.util.Iterator;

public class ForItrator {
    public static void main(String[] args) {
        ArrayList<Studentt> list = new ArrayList<Studentt>();
        list.add(new Studentt("张三", "22"));
        list.add(new Studentt("李四", "24"));
        list.add(new Studentt("王五", "26"));
        list.add(new Studentt("麻六", "28"));
        list.add(new Studentt("苏七", "30"));
        list.add(new Studentt("王八", "32"));
        list.add(new Studentt("李九", "34"));
        System.out.println(list);
        System.out.println(".........................................");
        //只是遍历用这个(只有数组和Collection集合可以用)
        for (Studentt studentt : list) {
            System.out.println(studentt);
        }
        System.out.println(".........................................");
        Iterator<Studentt> iterator = list.iterator();
        //删除元素用这个(只有数组和Collection集合可以用)
        while (iterator.hasNext()) {
            Studentt s = iterator.next();
            System.out.println(s.toString());
        }
        //带索引用这个
        System.out.println(".........................................");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i).toString());
        }
    }
}

class Studentt {
    private String name;
    private String age;

    @Override
    public String toString() {
        return "Studentt{" +
                "name='" + name + '\'' +
                ", age='" + age + '\'' +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public Studentt() {
    }

    public Studentt(String name, String age) {
        this.name = name;
        this.age = age;
    }
}